package cn.zyy.hotel.controller.admin;

import cn.zyy.hotel.entity.Checkout;
import cn.zyy.hotel.entity.Employee;
import cn.zyy.hotel.service.CheckoutService;
import cn.zyy.hotel.utils.SystemConstant;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/admin/checkout")
public class CheckoutAdminController {

    @Resource
    private CheckoutService checkoutService;

    //办理退房
    @RequiresPermissions("checkin:out")
    @RequestMapping("/addCheckout")
    public Object addCheckout(Checkout checkout, HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        //获取当前登录用户
        Employee employee = (Employee) session.getAttribute(SystemConstant.LOGINUSER);
        //创建人
        checkout.setCreatedBy(employee.getId());
        //调用办理退房方法
        if (checkoutService.addCheckout(checkout) > 0) {
            map.put(SystemConstant.SUCCESS,true);
            map.put(SystemConstant.MESSAGE,"退房成功");
        }else {
            map.put(SystemConstant.SUCCESS,false);
            map.put(SystemConstant.MESSAGE,"退房失败");
        }
        return map;
    }


}
